{php $no_left =true;}
{template '_header'}

<script type="text/javascript" src="../addons/ewei_shopv2/static/js/dist/area/cascade.js"></script>
<script type="text/javascript" src="../web/resource/js/lib/moment.js"></script>
<link rel="stylesheet" href="../web/resource/components/datetimepicker/jquery.datetimepicker.css">
<link rel="stylesheet" href="../web/resource/components/daterangepicker/daterangepicker.css">
<style type='text/css'>
    .tabs-container .form-group {overflow: hidden;}
    .tabs-container .tabs-left > .nav-tabs {}
    .tab-goods .nav li {float:left;}
    .spec_item_thumb {position: relative; width: 30px; height: 20px; padding: 0; border-left: none;}
    .spec_item_thumb i {position: absolute; top: -5px; right: -5px;}
    .multi-img-details, .multi-audio-details {margin-top:.5em;max-width: 700px; padding:0; }
    .multi-audio-details .multi-audio-item {width:155px; height: 40px; position:relative; float: left; margin-right: 5px;}
	.region-goods-details {
		background: #f8f8f8;
		margin-bottom: 10px;
		padding: 0 10px;
	}
	.region-goods-left{
		text-align: center;
		font-weight: bold;
		color: #333;
		font-size: 14px;
		padding: 20px 0;
	}
	.region-goods-right{
		border-left: 3px solid #fff;
		padding: 10px 10px;
	}
    {if $item['type']==4}
    .type-4 {display: none;}
    {/if}
</style>
<div class="page-header">
    当前位置：
    <span class="text-primary">
    {if !empty($item['id'])}编辑{else}添加{/if}商品 <small>{if !empty($item['id'])}修改【<span class="text-info">{$item['title']}</span>】{/if}{if !empty($merch_user['merchname'])}商户名称:【<span class="text-info">{$merch_user['merchname']}</span>】{/if}</small>
    </span>
</div>
<div class="page-content">
<div class="page-sub-toolbar">
	<span class=''>
		{ifp 'goods.add'}
        <a class="btn btn-primary btn-sm" href="{php echo webUrl('goods/add')}" >添加商品</a>
		{/if}
		{ifp 'goods.add'}
        <a class="btn btn-primary btn-sm" href="{php echo webUrl('goods/create')}" >快速添加商品</a>
		{/if}
    </span>
</div>
<form {ife 'goods' $item}action="" method="post"{/if} class="form-horizontal form-validate" enctype="multipart/form-data">
    <input type="hidden" id="tab" name="tab" value="#tab_basic" />
    <div class="tabs-container tab-goods">
        <div class="tabs-left">
            <ul class="nav nav-tabs" id="myTab">
                <li  {if empty($_GPC['tab']) || $_GPC['tab']=='basic'}class="active"{/if}><a href="#tab_basic">基本</a></li>
                <li  {if $_GPC['tab']=='option'}class="active"{/if} ><a href="#tab_option">库存/规格</a></li>
                <li {if $_GPC['tab']=='param'}class="active"{/if} ><a href="#tab_param">参数</a></li>
                <li {if $_GPC['tab']=='des'}class="active"{/if} ><a href="#tab_des">详情</a></li>
                <li {if $_GPC['tab']=='buy'}class="active"{/if} ><a href="#tab_buy">购买权限</a></li>
                <li {if $_GPC['tab']=='sale'}class="active"{/if} ><a href="#tab_sale">营销</a></li>
                <li {if $_GPC['tab']=='discount'}class="active"{/if} ><a href="#tab_discount">会员折扣</a></li>
                <li {if $_GPC['tab']=='share'}class="active"{/if} ><a href="#tab_share">分享关注</a></li>
                <li {if $_GPC['tab']=='notice'}class="active"{/if} ><a href="#tab_notice">卖家通知</a></li>

                {if !empty($com_set['level'])}
                <li {if $_GPC['tab']=='sell'}class="active"{/if}><a href="#tab_sell" id="a_sell">{if p('ccard') && $item['type'] == 20}返佣{else}分销{/if}</a></li>
                {/if}

				{if $merchid == 0 }
				<li {if $_GPC['tab']=='verify'}class="active"{/if} id="tab_nav_verify" {if $item['type']==3||$item['type']==5||($item['type']==2&&!empty($item['virtualsend']))}style="display:none;"{/if}><a href="#tab_verify">线下核销</a></li>

				{/if}
				
              	{if p('team_range')}
                <li {if $_GPC['tab']=='range'}class="active"{/if}><a href="#tab_range" id="a_range">极差</a></li>
                {/if}
              	
              	
                {if p('diyform')}
                <li {if $_GPC['tab']=='diyform'}class="active"{/if}><a href="#tab_diyform">自定义表单</a></li>
                {/if}

                {if $merchid == 0}
                <li {if $_GPC['tab']=='detaildiy'}class="active"{/if}><a href="#tab_detaildiy">店铺信息</a></li>
                {/if}

                {if p('diypage')}
                <li {if $_GPC['tab']=='diypage'}class="active"{/if}><a href="#tab_diypage">自定义模板</a></li>
                {/if}
                {if p('ccard')}
                <li class="ccard-group {if $_GPC['tab']=='ccard'}active{/if}" {if $item['type'] != 20}style="display:none;"{/if}><a href="#tab_ccard">充值说明</a></li>
                {/if}

				<li {if $item['type'] != 5}style="display:none;"{/if}   class="showverifygoods {if $_GPC['tab']=='verifygoods'}active{/if}" ><a href="#tab_verifygoods">记次/时核销</a></li>
				{if com('wxcard')}
				<li {if $item['type'] != 5}style="display:none;"{/if}   class="showverifygoodscard {if $_GPC['tab']=='verifygoodscard'} active{/if}" ><a href="#tab_verifygoodscard">微信会员卡设置</a></li>
				{/if}
            </ul>

            <div class="tab-content  ">
                <div class="tab-pane   {if empty($_GPC['tab']) || $_GPC['tab']=='basic'}active{/if}" id="tab_basic"><div class="panel-body">{template 'goods/tab/basic'}</div></div>
                <div class="tab-pane  {if $_GPC['tab']=='option'}active{/if}" id="tab_option"> <div class="panel-body">{template 'goods/tab/option'}</div></div>
                <div class="tab-pane {if $_GPC['tab']=='param'}active{/if}" id="tab_param"> <div class="panel-body">{template 'goods/tab/param'}</div></div>
                <div class="tab-pane {if $_GPC['tab']=='des'}active{/if}" id="tab_des"> <div class="panel-body" style='padding:0;'>{template 'goods/tab/des'}</div></div>
                <div class="tab-pane {if $_GPC['tab']=='buy'}active{/if}" id="tab_buy"> <div class="panel-body">{template 'goods/tab/buy'}</div></div>
                <div class="tab-pane {if $_GPC['tab']=='sale'}active{/if}" id="tab_sale" > <div class="panel-body" >{template 'goods/tab/sale'}</div></div>
                <div class="tab-pane {if $_GPC['tab']=='discount'}active{/if}" id="tab_discount"> <div class="panel-body">{template 'goods/tab/discount'}</div></div>
                <div class="tab-pane {if $_GPC['tab']=='share'}active{/if}" id="tab_share"> <div class="panel-body">{template 'goods/tab/share'}</div></div>
                <div class="tab-pane  {if $_GPC['tab']=='notice'}active{/if}" id="tab_notice"> <div class="panel-body">{template 'goods/tab/notice'}</div></div>
				<div class="tab-pane  {if $_GPC['tab']=='verifygoods'}active{/if}" id="tab_verifygoods"> <div class="panel-body">{template 'goods/tab/verifygoods'}</div></div>
				{if com('wxcard')}
				<div class="tab-pane  {if $_GPC['tab']=='verifygoodscard'}active{/if}" id="tab_verifygoodscard"> <div class="panel-body">{template 'goods/tab/verifygoodscard'}</div></div>
				{/if}
                {if p('commission') && !empty($com_set['level'])}
                <div class="tab-pane {if $_GPC['tab']=='sell'}active{/if}" id="tab_sell"> <div class="panel-body">
                    {if p('ccard')}
                    {template 'ccard/goods'}
                    {else}
                    {template 'commission/goods'}
                    {/if}
                </div></div>
                {/if}
				
              	{if p('team_range')}
                <div class="tab-pane {if $_GPC['tab']=='range'}active{/if}" id="tab_range">
                    <div class="panel-body">
                    {template 'team_range/goods'}
                    </div>
                </div>
                {/if}
              	
                {if $merchid == 0}
                <div class="tab-pane {if $_GPC['tab']=='verify'}active{/if}" id="tab_verify"> <div class="panel-body">{template 'goods/tab/verify'}</div></div>
                {/if}

                {if p('diyform')}
                <div class="tab-pane {if $_GPC['tab']=='diyform'}active{/if}" id="tab_diyform"> <div class="panel-body">{template 'diyform/goods'}</div></div>
                {/if}

                {if $merchid == 0}
                <div class="tab-pane {if $_GPC['tab']=='detaildiy'}active{/if}" id="tab_detaildiy"> <div class="panel-body">{template 'goods/tab/detaildiy'}</div></div>
                {/if}

                {if p('diypage')}
                <div class="tab-pane {if $_GPC['tab']=='diypage'}active{/if}" id="tab_diypage"> <div class="panel-body">{template 'diypage/invoke/goods'}</div></div>
                {/if}

                {if p('ccard')}
                <div class="tab-pane {if $_GPC['tab']=='ccard'}active{/if}" id="tab_ccard"> <div class="panel-body">{template 'ccard/explain'}</div></div>
                {/if}


            </div>
        </div>
    </div>
    {ife 'goods' $item}
    <div class="form-group">
        <label class="col-sm-2 control-label"></label>
        <div class="col-sm-9 subtitle">
            <input type="submit" value="保存商品" class="btn btn-primary"/>
			<a class="btn btn-default" href="{php echo webUrl('goods',array('goodsfrom'=>$_GPC['goodsfrom'], 'page'=>$_GPC['page']))}">返回列表</a>
        </div>
    </div>
    {/if}
</form>
</div>

<script type="text/javascript">
	window.type = "{$item['type']}";
	window.virtual = "{$item['virtual']}";
	require(['bootstrap'], function () {
		$('#myTab a').click(function (e) {
			$('#tab').val( $(this).attr('href'));
			e.preventDefault();
			$(this).tab('show');
		})
	});
	$(function () {

		$(':radio[name=isverify]').click(function () {
			window.type = $("input[name='isverify']:checked").val();

			if (window.type == '2') {
				$(':checkbox[name=cash]').attr("checked",false);
				$(':checkbox[name=cash]').parent().hide();
			} else {
				$(':checkbox[name=cash]').parent().show();
			}
		});
		$(':radio[name=ispresell]').click(function () {
			window.ispresell = $("input[name='ispresell']:checked").val();
			if(window.ispresell==0){
				$(".presell_info").hide();
			}else{
				$(".presell_info").show();
			}
		});
        $(':radio[name=isverify]').click(function () {
            if(window.type=='1'||window.type=='4'){

                if( $("input[name='isverify']:checked").val() !=2){
                    $('.dispatch_info').show();
                }
                else {
                    $('.dispatch_info').hide();
                }

            } else {
                $('.dispatch_info').hide();
            }



        });
		$(':radio[name=type]').click(function () {
			window.type = $("input[name='type']:checked").val();
			window.virtual = $("#virtual").val();
			if(window.type=='1'||window.type=='4'){
				$('.dispatch_info').show();
			} else {
				$('.dispatch_info').hide();
			}
			if (window.type == '2') {
				$('.send-group').show();
			} else {
				$('.send-group').hide();
			}
			if (window.type == '3') {
				if ($('#virtual').val() == '0') {
					$('.choosetemp').show();
				}
				// 商品类型如果为虚拟卡密则不允许修改库存
                $('#weight').attr('readonly',true);
                $('#total').attr('readonly',true);
			}
			if (window.type == '2' || window.type == '3'|| window.type == '5') {
				$(':checkbox[name=cash]').attr("checked",false);
				$(':checkbox[name=cash]').parent().hide();
			} else {
				$(':checkbox[name=cash]').parent().show();

			}

            if(window.type=='4'){
                $('.type-4').hide();
            }else{
                $('.type-4').show();
            }
		})

        $('#virtual').change(function(){
            window.virtual = $(this).val();
        })
		$(":checkbox[name='buyshow']").click(function () {
			if ($(this).prop('checked')) {
				$(".bcontent").show();
			}
			else {
				$(".bcontent").hide();
			}
		})

		$(':radio[name=buyshow]').click(function () {
			window.buyshow = $("input[name='buyshow']:checked").val();

			if(window.buyshow=='1'){
				$('.bcontent').show();
			} else {
				$('.bcontent').hide();
			}
		})
	})

	window.optionchanged = false;

	$('form').submit(function(){
		var check = true;

		$(".tp_title,.tp_name").each(function(){
			var val = $(this).val();
			if(!val){
				$('#myTab a[href="#tab_diyform"]').tab('show');
				$(this).focus(),$('form').attr('stop',1),tip.msgbox.err('自定义表单字段名称不能为空!');
				check =false;
				return false;
			}
		});

		var diyformtype = $(':radio[name=diyformtype]:checked').val();

		if (diyformtype == 2) {
			if(kw == 0) {
				$('#myTab a[href="#tab_diyform"]').tab('show');
				$(this).focus(),$('form').attr('stop',1),tip.msgbox.err('请先添加自定义表单字段再提交!');
				check =false;
				return false;
			}
		}

		if(!check){return false;}

		window.type = $("input[name='type']:checked").val();
		window.virtual = $("#virtual").val();
		if ($("#goodsname").isEmpty()) {
			$('#myTab a[href="#tab_basic"]').tab('show');
			$('form').attr('stop',1);
			$(this).focus(),$('form').attr('stop',1),tip.msgbox.err('请填写商品名称!');
			return false;
		}

		var inum = 0;
		$('.gimgs').find('.img-thumbnail').each(function(){
			inum++;
		});
		if(inum == 0){
			$('#myTab a[href="#tab_basic"]').tab('show');
			$('form').attr('stop',1),tip.msgbox.err('请上传商品图片!');
			return false;
		}


		var full = true;
		if (window.type == '3') {
			if (window.virtual != '0') {  //如果单规格，不能有规格
				if ($('#hasoption').get(0).checked) {
					$('form').attr('stop',1),tip.msgbox.err('您的商品类型为：虚拟物品(卡密)的单规格形式，需要关闭商品规格！');
					return false;
				}
			}
			else {

				var has = false;
				$('.spec_item_virtual').each(function () {
					has = true;
					if ($(this).val() == '' || $(this).val() == '0') {
						$('#myTab a[href="#tab_option"]').tab('show');
						$(this).next().focus();
						$('form').attr('stop',1),tip.msgbox.err('请选择虚拟物品模板!');
						full = false;
						return false;
					}
				});
				if (!has) {
					$('#myTab a[href="#tab_option"]').tab('show');
					$('form').attr('stop',1),tip.msgbox.err('您的商品类型为：虚拟物品(卡密)的多规格形式，请添加规格！');
					return false;
				}
			}
		}
		else if (window.type == '5') {
			if ($('#hasoption').get(0).checked) {
				$('form').attr('stop',1),tip.msgbox.err('您的商品类型为：核销产品，无法设置多商品规格！');
				return false;
			}
		}
		else if(window.type=='10'){
			var spec_itemlen = $(".spec_item").length;
			if (!$('#hasoption').get(0).checked || spec_itemlen<1) {
				$('#myTab a[href="#tab_option"]').tab('show');
				$('form').attr('stop',1),tip.msgbox.err('您的商品类型为：话费流量充值，需要开启并设置商品规格！');
				return false;
			}
			if(spec_itemlen>1){
				$('#myTab a[href="#tab_option"]').tab('show');
				$('form').attr('stop',1),tip.msgbox.err('您的商品类型为：话费流量充值，只可添加一个规格！');
				return false;
			}
		}
		if (!full) {
			return false;
		}

		full = checkoption();
		if (!full) {
			$('form').attr('stop',1),tip.msgbox.err('请输入规格名称!');
			return false;
		}
		if (optionchanged) {
			$('#myTab a[href="#tab_option"]').tab('show');
			$('form').attr('stop',1),tip.msgbox.err('规格数据有变动，请重新点击 [刷新规格项目表] 按钮!');
			return false;
		}
		var spec_item_title = 1;
		if($('#hasoption').get(0).checked){
			$(".spec_item").each(function (i) {
				var _this = this;
				if($(_this).find(".spec_item_title").length == 0){
					spec_item_title = 0;
				}
			});
		}
		if(spec_item_title == 0){
			$('form').attr('stop',1),tip.msgbox.err('详细规格没有填写,请填写详细规格!');
			return false;
		}
		$('form').attr('stop',1);
		//处理规格
		optionArray();
		isdiscountDiscountsArray();
		discountArray();
		commissionArray();
		$('form').removeAttr('stop');
		return true;
	});

	function optionArray()
	{
		var option_stock = new Array();
		$('.option_stock').each(function (index,item) {
			option_stock.push($(item).val());
		});

		var option_id = new Array();
		$('.option_id').each(function (index,item) {
			option_id.push($(item).val());
		});

		var option_ids = new Array();
		$('.option_ids').each(function (index,item) {
			option_ids.push($(item).val());
		});

		var option_title = new Array();
		$('.option_title').each(function (index,item) {
			option_title.push($(item).val());
		});

		var option_virtual = new Array();
		$('.option_virtual').each(function (index,item) {
			option_virtual.push($(item).val());
		});

		var option_marketprice = new Array();
		$('.option_marketprice').each(function (index,item) {
			option_marketprice.push($(item).val());
		});
		var option_presellprice = new Array();
		$('.option_presell').each(function (index,item) {
			option_presellprice.push($(item).val());
		});

		var option_productprice = new Array();
		$('.option_productprice').each(function (index,item) {
			option_productprice.push($(item).val());
		});

		var option_costprice = new Array();
		$('.option_costprice').each(function (index,item) {
			option_costprice.push($(item).val());
		});

		var option_goodssn = new Array();
		$('.option_goodssn').each(function (index,item) {
			option_goodssn.push($(item).val());
		});

		var option_productsn = new Array();
		$('.option_productsn').each(function (index,item) {
			option_productsn.push($(item).val());
		});

		var option_weight = new Array();
		$('.option_weight').each(function (index,item) {
			option_weight.push($(item).val());
		});

		var options = {
			option_stock : option_stock,
			option_id : option_id,
			option_ids : option_ids,
			option_title : option_title,
			option_presellprice : option_presellprice,
			option_marketprice : option_marketprice,
			option_productprice : option_productprice,
			option_costprice : option_costprice,
			option_goodssn : option_goodssn,
			option_productsn : option_productsn,
			option_weight : option_weight,
			option_virtual : option_virtual
		};
		$("input[name='optionArray']").val(JSON.stringify(options));
	}

	function isdiscountDiscountsArray()
	{

		{loop $levels $level}
		var isdiscount_discounts_{$level['key']} = new Array();
		$(".isdiscount_discounts_{$level['key']}").each(function (index,item) {
			isdiscount_discounts_{$level['key']}.push($(item).val());
		});
		{/loop}

		var isdiscount_discounts_id = new Array();
		$('.isdiscount_discounts_id').each(function (index,item) {
			isdiscount_discounts_id.push($(item).val());
		});

		var isdiscount_discounts_ids = new Array();
		$('.isdiscount_discounts_ids').each(function (index,item) {
			isdiscount_discounts_ids.push($(item).val());
		});

		var isdiscount_discounts_title = new Array();
		$('.isdiscount_discounts_title').each(function (index,item) {
			isdiscount_discounts_title.push($(item).val());
		});

		var isdiscount_discounts_virtual = new Array();
		$('.isdiscount_discounts_virtual').each(function (index,item) {
			isdiscount_discounts_virtual.push($(item).val());
		});

		var options = {
		{loop $levels $level}
		isdiscount_discounts_{$level['key']} : isdiscount_discounts_{$level['key']},
		{/loop}
		isdiscount_discounts_id : isdiscount_discounts_id,
				isdiscount_discounts_ids : isdiscount_discounts_ids,
			isdiscount_discounts_title : isdiscount_discounts_title,
			isdiscount_discounts_virtual : isdiscount_discounts_virtual
	};
		$("input[name='isdiscountDiscountsArray']").val(JSON.stringify(options));
	}

	function discountArray()
	{

		{loop $levels $level}
		var discount_{$level['key']} = new Array();
		$(".discount_{$level['key']}").each(function (index,item) {
			discount_{$level['key']}.push($(item).val());
		});
		{/loop}

		var discount_id = new Array();
		$('.discount_id').each(function (index,item) {
			discount_id.push($(item).val());
		});

		var discount_ids = new Array();
		$('.discount_ids').each(function (index,item) {
			discount_ids.push($(item).val());
		});

		var discount_title = new Array();
		$('.discount_title').each(function (index,item) {
			discount_title.push($(item).val());
		});

		var discount_virtual = new Array();
		$('.discount_virtual').each(function (index,item) {
			discount_virtual.push($(item).val());
		});

		var options = {
		{loop $levels $level}
		discount_{$level['key']} : discount_{$level['key']},
		{/loop}
		discount_id : discount_id,
				discount_ids : discount_ids,
			discount_title : discount_title,
			discount_virtual : discount_virtual
	};
		$("input[name='discountArray']").val(JSON.stringify(options));
	}

	function commissionArray()
	{
        if(!$('#hasoption').get(0).checked) {
            return false;
        }
	    var specs = [];
		$(".spec_item").each(function (i) {
			var _this = $(this);

			var spec = {
				id: _this.find(".spec_id").val(),
				title: _this.find(".spec_title").val()
			};

			var items = [];
			_this.find(".spec_item_item").each(function () {
				var __this = $(this);
				var item = {
					id: __this.find(".spec_item_id").val(),
					title: __this.find(".spec_item_title").val(),
					virtual: __this.find(".spec_item_virtual").val(),
					show: __this.find(".spec_item_show").get(0).checked ? "1" : "0"
				}
				items.push(item);
			});
			spec.items = items;
			specs.push(spec);
		});
		specs.sort(function (x, y) {
			if (x.items.length > y.items.length) {
				return 1;
			}
			if (x.items.length < y.items.length) {
				return -1;
			}
		});

		var len = specs.length;
		var newlen = 1;
		var h = new Array(len);
		var rowspans = new Array(len);
		for (var i = 0; i < len; i++) {
			var itemlen = specs[i].items.length;
			if (itemlen <= 0) {
				itemlen = 1
			}
			newlen *= itemlen;
			h[i] = new Array(newlen);
			for (var j = 0; j < newlen; j++) {
				h[i][j] = new Array();
			}
			var l = specs[i].items.length;
			rowspans[i] = 1;
			for (j = i + 1; j < len; j++) {
				rowspans[i] *= specs[j].items.length;
			}
		}

		for (var m = 0; m < len; m++) {
			var k = 0, kid = 0, n = 0;
			for (var j = 0; j < newlen; j++) {
				var rowspan = rowspans[m];
				if (j % rowspan == 0) {
					h[m][j] = {
						title: specs[m].items[kid].title,
						virtual: specs[m].items[kid].virtual,
						id: specs[m].items[kid].id
					};
				}
				else {
					h[m][j] = {
						title: specs[m].items[kid].title,
						virtual: specs[m].items[kid].virtual,
						id: specs[m].items[kid].id
					};
				}
				n++;
				if (n == rowspan) {
					kid++;
					if (kid > specs[m].items.length - 1) {
						kid = 0;
					}
					n = 0;
				}
			}
		}

		var commission = {};
		var commission_level = {php echo json_encode($commission_level)};
		for (var i = 0; i < newlen; i++) {
			var ids = [];
			for (var j = 0; j < len; j++) {
				ids.push(h[j][i].id);
			}
			ids = ids.join('_');
			$.each(commission_level,function (key,val) {
				if(val.key == 'default')
				{
					var kkk = "commission_level_"+val.key+"_"+ids;
					commission[kkk] = {};
					$("input[data-name=commission_level_"+val.key+"_"+ids+"]").each(function (k,v) {
						commission[kkk][k] = $(v).val();
					});
				}
				else
				{
					var kkk = "commission_level_"+val.id+"_"+ids;
					commission[kkk] = {};
					$("input[data-name=commission_level_"+val.id+"_"+ids+"]").each(function (k,v) {
						commission[kkk][k] = $(v).val();
					});
					var kkk = "commission_level_"+val.id+"_"+ids;
					commission[kkk] = {};
					$("input[data-name=commission_level_"+val.id+"_"+ids+"]").each(function (k,v) {
						commission[kkk][k] = $(v).val();
					});
				}
			})
		}

		var commission_id = new Array();
		$('.commission_id').each(function (index,item) {
			commission_id.push($(item).val());
		});

		var commission_ids = new Array();
		$('.commission_ids').each(function (index,item) {
			commission_ids.push($(item).val());
		});

		var commission_title = new Array();
		$('.commission_title').each(function (index,item) {
			commission_title.push($(item).val());
		});

		var commission_virtual = new Array();
		$('.commission_virtual').each(function (index,item) {
			commission_virtual.push($(item).val());
		});



		var options = {
			commission : commission,
			commission_id : commission_id,
			commission_ids : commission_ids,
			commission_title : commission_title,
			commission_virtual : commission_virtual
		};
		$("input[name='commissionArray']").val(JSON.stringify(options));
	}

	function checkoption() {

		var full = true;
		var $spec_title = $(".spec_title");
		var $spec_item_title = $(".spec_item_title");
		if ($("#hasoption").get(0).checked) {
			if($spec_title.length==0){
				$('#myTab a[href="#tab_option"]').tab('show');
				full = false;
			}
			if($spec_item_title.length==0){
				$('#myTab a[href="#tab_option"]').tab('show');
				full = false;
			}
		}
		if (!full) {
			return false;
		}
		return full;
	}

	function type_change(type) {
		if(type == 4) {
			$(".interval").show();
			$(".price").hide();
			$(".minbuy").hide();
			$(".wholesalewarning").show();
		}else{
			$(".interval").hide();
			$(".price").show();
			$(".minbuy").show();
			$(".wholesalewarning").hide();
		}

		if(type == 5) {
			$(".showverifygoods").show();
			$(".showverifygoodscard").show();
			$('#product').hide();
			$('#type_virtual').hide();
			$("#tab_nav_verify").hide();
            $("[for|='totalcnf2']").show();
            $("[for|='totalcnf3']").show();
		}else
		{
			$(".showverifygoods").hide();
			$(".showverifygoodscard").hide();
		}

		if(type == 1||type == 4) {
			$('#product').show();
			$('#type_virtual').hide();
			$('.entity').show();
			$("#tab_nav_verify").show();
            $("[for|='totalcnf2']").show();
            $("[for|='totalcnf3']").show();
		} else if(type == 2) {
			$('#product').hide();
			$('#type_virtual').hide();
			$('.entity').hide();
			if($("input[name='virtualsend']:checked").val()==1) {
				$("#tab_nav_verify").hide();
			}else{
				$("#tab_nav_verify").show();
			}
            $("[for|='totalcnf2']").show();
            $("[for|='totalcnf3']").show();
		} else if(type == 3) {
			$('#type_virtual').show();
			$('.entity').hide();
			$("#tab_nav_verify").hide();
            $("[for|='totalcnf2']").hide();
            $("[for|='totalcnf3']").hide();
		}else if(type == 10) {
			$('#type_virtual').hide();
			$('#product').hide();
			$('.entity').hide();
			$("#tab_nav_verify").hide();
            $("[for|='totalcnf2']").show();
            $("[for|='totalcnf3']").show();
		}
	}

</script>
{template '_footer'}
